package com.example.demo.task;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.concurrent.TimeUnit;

public class TimeTask implements Runnable {
    @Override
    public void run() {
        SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss");
        try {
            // 倒计时1分钟，每秒输出一次时间
            for (int i = 60; i > 0; i--) {
                System.out.println("当前时间: " + sdf.format(new Date()) + "，剩余时间: " + i + "秒");
                TimeUnit.SECONDS.sleep(1);
            }
            System.out.println("倒计时结束！");
        } catch (InterruptedException e) {
            Thread.currentThread().interrupt();
        }
    }
}